import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
//别名
import path from "path";
//自动导入
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import IconsResolver from "unplugin-icons/resolver";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import Icons from "unplugin-icons/vite";
//svg
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";

// https://vite.dev/config/
export default defineConfig({
	plugins: [
		vue(),
		AutoImport({
			// 自动导入 Vue 相关函数，如：ref, reactive, toRef 等
			imports: ["vue"],
			resolvers: [
				// 自动导入 Element Plus 相关函数，如：ElMessage, ElMessageBox... (带样式)
				ElementPlusResolver(),
				// 自动导入图标组件
				IconsResolver({}),
			],
			vueTemplate: true, // 是否在 vue 模板中自动导入
		}),
		Components({
			// 自动导入 Element Plus 相关函数，如：ElMessage, ElMessageBox... (带样式)
			resolvers: [
				// 自动导入 Element Plus 组件
				ElementPlusResolver(),
				// 自动注册图标组件
				IconsResolver({
					// element-plus图标库，其他图标库 https://icon-sets.iconify.design/
					enabledCollections: ["ep"],
				}),
			],
		}),
		Icons({
			// 自动安装图标库
			autoInstall: true,
		}),
		createSvgIconsPlugin({
			// 指定需要缓存的图标文件夹
			iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
			// 指定symbolId格式
			symbolId: "icon-[dir]-[name]",
		}),
	],
	resolve: {
		// https://cn.vitejs.dev/config/#resolve-alias
		alias: {
			"@": path.resolve(__dirname, "./src"),
			"@components": path.resolve(__dirname, "./src/components"),
			"@views": path.resolve(__dirname, "./src/views"),
			"@assets": path.resolve(__dirname, "./src/assets"),
		},
		// https://cn.vitejs.dev/config/#resolve-extensions
		extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
	},
});